package com.learn.component.handler;

import com.learn.component.service.HelloService;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletContext;

@Controller
public class HelloHandler {

    @Autowired
    HelloService helloService;
    @Autowired
    ServletContext servletContext;

    Logger logger = LoggerFactory.getLogger(this.getClass());
    @RequestMapping("/hello/world")
    public String helloWorld(Model model) {

        String message = helloService.getMessage();
        model.addAttribute("message", message);

        Object springIOC =  servletContext.getAttribute("org.springframework.web.context.WebApplicationContext.ROOT");
        Object springMVCIOC =  servletContext.getAttribute("org.springframework.web.servlet.FrameworkServlet" + ".CONTEXT.DispatcherServlet");
        logger.debug(springIOC.toString());
        logger.debug(springMVCIOC.toString());
        return "target";
    }
}
